//
//  UserDefault+Extension.swift
//  SwiftProject
//
//  Created by qindong on 2021/3/12.
//

import Foundation

extension UserDefaults {
    // 批量存储
    func store(keys: [String], values: [Any]) {
        if keys.count != values.count && keys.count == 0 {
            return
        }
        for (index, value) in keys.enumerated() {
            set(values[index], forKey: value)
            print("*** STORE *** \(value) : \(values[index]) ***")
        }
        synchronize()
    }

    class func setUserModel(_ data : Data) {
        standard.set(data, forKey: "userData")
        standard.synchronize()
    }

    class func getUserModel() -> Data? {
        standard.value(forKey: "userData") as? Data ?? nil
    }

    class func removeUserModel() {
        standard.removeObject(forKey: "userData")
        standard.synchronize()
    }
}

